#include <bits/stdc++.h>
using namespace std;

#define MAX 200200

int n, ans;
char S[MAX], T[MAX];
bool vis[MAX];
int des[MAX], ind[MAX];
set<int> st;

void bfs_cut() {
  queue<int> Q;
  for (int i = 'a'; i <= 'z'; ++i)
    if (!ind[i])
      Q.push(i);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    vis[u] = true;
    if (!des[u])
      continue;
    int v = des[u];
    if (!vis[v])
      Q.push(v);
  }
}

void dfs(int u) {
  vis[u] = true;
  if (des[u] && !vis[des[u]])
    dfs(des[u]);
}

int main() {
  scanf("%d", &n);
  scanf("%s %s", S + 1, T + 1);

  for (int i = 1; i <= n; ++i) {
    if ((!des[S[i]] || des[S[i]] == T[i])) {
      des[S[i]] = T[i];
      if (S[i] != T[i])
        st.insert(T[i]);
    } else {
      puts("-1");
      exit(0);
    }
  }

  if (st.size() == 26) {
    for (int i = 1; i <= n; ++i)
      if (S[i] != T[i]) {
        puts("-1");
        exit(0);
      }
    puts("0");
    return 0;
  }

  memset(des, 0, sizeof(des));
  memset(ind, 0, sizeof(ind));

  for (int i = 1; i <= n; ++i) {
    if (des[S[i]] == 0 && S[i] != T[i]) {
      ++ans;
      des[S[i]] = T[i];
      ++ind[T[i]];
    }
  }

  bfs_cut();

  for (int i = 'a'; i <= 'z'; ++i) {
    if (!vis[i]) {
      ++ans;
      dfs(i);
    }
  }

  printf("%d\n", ans);
  return 0;
}
